//
//  HMAudioPlayerShareView.m
//  HowToDo
//
//  Created by mynSoo on 2017/1/9.
//  Copyright © 2017年 KY. All rights reserved.
//

#import "HMAudioPlayerShareView.h"
#import <Masonry.h>

@implementation HMAudioPlayerShareView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if(self)
    {
        [self installUI];
    }
    return self;
}

- (void)installUI
{
    self.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 225);
    
    self.backgroundColor = [UIColor whiteColor];
    // shareFriendsBtn
    UIButton *shareFriendsBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [shareFriendsBtn setImage:[UIImage imageNamed:@"hot_share_friends"] forState:UIControlStateNormal];
    
    [self addSubview:shareFriendsBtn];
    
    // shareFriendsLabel
    UILabel *shareFriendsLabel = [[UILabel alloc]init];
    
    shareFriendsLabel.text = @"微信好友";
    
    shareFriendsLabel.textColor = [UIColor colorWithHex:0xbdbdbd];
    
    [self addSubview:shareFriendsLabel];
    
    // shareWechatBtn
    UIButton *shareWechatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self addSubview:shareWechatBtn];
    
    // shareWechatLabel
    UILabel *shareWechatLabel = [[UILabel alloc]init];
    
    shareWechatLabel.text = @"朋友圈";
    
    shareWechatLabel.textColor = [UIColor colorWithHex:0xbdbdbd];
    
    [self addSubview:shareWechatLabel];
    
    NSArray *arr = @[shareFriendsBtn,shareWechatBtn];
    
    // sepratorView
    UIView *sepratorView = [[UIView alloc]init];
    
    sepratorView.backgroundColor = [UIColor colorWithHex:0xdddddd];
    
    [self addSubview:sepratorView];
    
    
    UIButton *cancleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [self addSubview:cancleBtn];
    
    [shareWechatBtn setImage:[UIImage imageNamed:@"hot_share_wechat"] forState:UIControlStateNormal];
    
    [arr mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:0 leadSpacing:0 tailSpacing:0];
    
    [arr mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(20);
        // make.height.offset(130);
    }];
    
    [shareWechatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(shareWechatBtn.mas_bottom).offset(11);
        make.centerX.equalTo(shareWechatBtn);
    }];
    
    [shareFriendsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(shareFriendsBtn.mas_bottom).offset(11);
        make.centerX.equalTo(shareFriendsBtn);
    }];

    [sepratorView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(171);
        make.centerX.offset(0);
        make.left.offset(10);
        make.right.offset(-10);
        make.height.offset(1.0 / [UIScreen mainScreen].scale);
    }];

    [cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(sepratorView.mas_bottom);
        make.left.right.bottom.offset(0);
    }];
    
    
    [cancleBtn setTitleColor:[UIColor colorWithHex:0xffc171] forState:UIControlStateNormal];
    
    [cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
    
    // action
    
    [shareWechatBtn addTarget:self action:@selector(clickShareWechatBtn) forControlEvents:UIControlEventTouchDown];
    
    [shareFriendsBtn addTarget:self action:@selector(clickShareFriendBtn) forControlEvents:UIControlEventTouchDown];
    
    [cancleBtn addTarget:self action:@selector(clickCancleBtn) forControlEvents:UIControlEventTouchDown];
    
}

- (void)clickShareFriendBtn
{
    [[HMNetWorkTool sharedTool]shareTextToPlatformType:2 andShareMessage:@"欢迎使用获得APP"];
    if(_wechatBlock)
    {
        _wechatBlock();
    }
}

- (void)clickShareWechatBtn
{
    [[HMNetWorkTool sharedTool]shareTextToPlatformType:1 andShareMessage:@"欢迎使用获得APP"];
    if(_shareFriendBlock)
    {
        _shareFriendBlock();
    }
}

- (void)clickCancleBtn
{
    if(_cancleBlock)
    {
        _cancleBlock();
    }
        
}
@end
